package com.century.sjt.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.century.sjt.R;
import com.century.sjt.entity.MgridView;

import java.util.List;

/**
 * @author:周玲波
 * @Description: GridView适配器
 * @date : 2016/8/17 14:21
 */
public class GridViewAdapter extends BaseAdapter {
    List<MgridView> gvList = null;
    LayoutInflater inflater;
    Typeface iconfont;
    public GridViewAdapter(List<MgridView> gvList, Context context, Typeface iconfont ) {
        this.gvList = gvList;
        inflater = LayoutInflater.from(context);
        this.iconfont=iconfont;
    }

    @Override
    public int getCount() {
        return gvList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = null;
        if (convertView == null) {
            holder = new Holder();
            convertView = inflater.inflate(R.layout.wallet_gv_item, null);
            holder.icon = (TextView) convertView.findViewById(R.id.wallet_gvitem_icon);
            holder.tv = (TextView) convertView.findViewById(R.id.wallet_gvitem_tv);
            convertView.setTag(holder);
        }else{
            holder= (Holder) convertView.getTag();
        }
        holder.tv.setText(gvList.get(position).getName());
        holder.icon.setText(gvList.get(position).getIcon());
        holder.icon.setTypeface(iconfont);
        return convertView;
    }
}

class Holder {
    TextView icon;
    TextView tv;

}